/*     */ package com.zimbra.cs.redolog.op;
/*     */ 
/*     */ import com.zimbra.common.calendar.ICalTimeZone;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.MailboxOperation;
/*     */ import com.zimbra.cs.mailbox.Metadata;
/*     */ import com.zimbra.cs.mailbox.calendar.Util;
/*     */ import com.zimbra.cs.mailbox.calendar.tzfixup.TimeZoneFixupRules;
/*     */ import com.zimbra.cs.redolog.RedoLogInput;
/*     */ import com.zimbra.cs.redolog.RedoLogOutput;
/*     */ import java.io.IOException;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class FixCalendarItemTZ
/*     */   extends RedoableOp
/*     */ {
/*     */   private int mId;
/*     */   private Map<String, ICalTimeZone> mReplacementMap;
/*     */   
/*     */   public FixCalendarItemTZ()
/*     */   {
/*  42 */     super(MailboxOperation.FixCalendarItemTZ);
/*     */   }
/*     */   
/*     */   public FixCalendarItemTZ(int mailboxId, int itemId) {
/*  46 */     this();
/*  47 */     setMailboxId(mailboxId);
/*  48 */     this.mId = itemId;
/*     */   }
/*     */   
/*     */   public void setReplacementMap(Map<String, ICalTimeZone> replacementMap) {
/*  52 */     this.mReplacementMap = replacementMap;
/*     */   }
/*     */   
/*     */   protected void serializeData(RedoLogOutput out) throws IOException
/*     */   {
/*  57 */     out.writeInt(this.mId);
/*  58 */     if (this.mReplacementMap != null) {
/*  59 */       out.writeInt(this.mReplacementMap.size());
/*  60 */       for (Map.Entry<String, ICalTimeZone> entry : this.mReplacementMap.entrySet()) {
/*  61 */         String tzid = (String)entry.getKey();
/*  62 */         ICalTimeZone newTZ = (ICalTimeZone)entry.getValue();
/*  63 */         String newTZMeta = null;
/*  64 */         if (newTZ != null)
/*  65 */           newTZMeta = Util.encodeAsMetadata(newTZ).toString();
/*  66 */         out.writeUTF(tzid);
/*  67 */         out.writeUTF(newTZMeta);
/*     */       }
/*     */     } else {
/*  70 */       out.writeInt(0);
/*     */     }
/*     */   }
/*     */   
/*     */   protected void deserializeData(RedoLogInput in) throws IOException
/*     */   {
/*  76 */     this.mId = in.readInt();
/*  77 */     int numReplacements = in.readInt();
/*  78 */     if (numReplacements > 0) {
/*  79 */       this.mReplacementMap = new HashMap(numReplacements);
/*  80 */       for (int i = 0; i < numReplacements; i++) {
/*  81 */         String tzid = in.readUTF();
/*  82 */         String newTZMeta = in.readUTF();
/*     */         try {
/*  84 */           ICalTimeZone newTZ = null;
/*  85 */           if (newTZMeta != null)
/*  86 */             newTZ = Util.decodeTimeZoneFromMetadata(new Metadata(newTZMeta));
/*  87 */           this.mReplacementMap.put(tzid, newTZ);
/*     */         } catch (ServiceException e) {
/*  89 */           IOException ioe = new IOException("Error deserializing timezone");
/*  90 */           ioe.initCause(e);
/*  91 */           throw ioe;
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   protected String getPrintableData()
/*     */   {
/*  99 */     StringBuilder sb = new StringBuilder("id=");
/* 100 */     sb.append(this.mId);
/* 101 */     if (this.mReplacementMap != null) {
/* 102 */       sb.append(", replacementMap=[");
/* 103 */       for (Map.Entry<String, ICalTimeZone> entry : this.mReplacementMap.entrySet()) {
/* 104 */         String tzid = (String)entry.getKey();
/* 105 */         ICalTimeZone newTZ = (ICalTimeZone)entry.getValue();
/* 106 */         sb.append("\n");
/* 107 */         sb.append("oldTZID=\"").append(tzid).append("\"\n==> newTZ: ").append(newTZ.toString()).append(",");
/*     */       }
/* 109 */       sb.append("]");
/*     */     }
/* 111 */     return sb.toString();
/*     */   }
/*     */   
/*     */   public void redo() throws Exception
/*     */   {
/* 116 */     Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
/* 117 */     TimeZoneFixupRules rules = new TimeZoneFixupRules(this.mReplacementMap);
/* 118 */     mbox.fixCalendarItemTZ(getOperationContext(), this.mId, rules);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/op/FixCalendarItemTZ.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */